home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / ABox.v1.8 / CPlus Files / ABUEnvDragMgr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-23  |  9.6 KB  |  383 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABUEnvDragMgr.c
  15.  
  16. NAME
  17.     ABUEnvDragMgr.c, part of the ABox project source code,
  18.     responsible for mix-in handling the AboutBox DragMgr environment stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                netromancr@aol.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <netromancr@aol.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     27 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     28-july-94    -    ty    -    fixes to watch for Region errors during drag process
  38.     1-aug-94    -    ty    -    added code to deal with the DragSendProc
  39.     27-apr-95    -    ty    -    1.0.7--fixed detection for the drag manager, since
  40.                                 a bug was reported when running on Sys 7.1
  41.                                 French-Canadian system (!)...thanks simon!
  42.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  43.                             release and the associated Universal Headers from Apple:
  44.                             most methods that returned references now have "Ref" at
  45.                             the end of their methods names to prevent possible collisions
  46.                             with datatypes and classes of the same name (older versions
  47.                             of the compiler didn't have a problem with this).
  48.  
  49. */
  50.  
  51. /*===========================================================================*/
  52.  
  53. /*======= Segmentation directives ========*/
  54.  
  55. #ifdef USE_MANUAL_SEGMENTATION
  56. #pragma segment ty
  57. #endif
  58.  
  59. /*============ Header files ==============*/
  60.     
  61. #include     "ABUEnvDragMgr.h"
  62.  
  63. /*=============== Globals ================*/
  64.  
  65. /*================ CODE ==================*/
  66.  
  67.  
  68. /*=============================== ABUEnvDragMgr::ABUEnvDragMgr ================================*/
  69. ABUEnvDragMgr::ABUEnvDragMgr(void)
  70. {
  71.     mDragReference = NULL;
  72.     mItemReference = (ItemReference)1;
  73.     mDragRegion = NULL;
  74.     mDragRect.left = mDragRect.right = mDragRect.top = mDragRect.bottom = 0;
  75.     mDragUPP = NULL;
  76.     mDragMgrEvent = NULL;
  77.     mDragInitialized = false;
  78. }    // end ABUEnvDragMgr
  79.  
  80.  
  81.  
  82. /*=============================== ABUEnvDragMgr::~ABUEnvDragMgr ================================*/
  83. ABUEnvDragMgr::~ABUEnvDragMgr(void)
  84. {
  85.     this->End();
  86. }    // end ~ABUEnvDragMgr
  87.  
  88.  
  89.  
  90. /*=============================== ABUEnvDragMgr::IsPresent ================================*/
  91. Boolean    ABUEnvDragMgr::IsPresent(void)
  92. {
  93.     if (this->CheckGestalt(gestaltDragMgrAttr) == noErr)
  94.     {
  95.         this->IndicatorRef() = this->Attribute(0);
  96.             
  97.     } else {
  98.         this->IndicatorRef() = false;
  99.     }
  100.  
  101.     return this->IndicatorRef();
  102. }    // end IsPresent
  103.  
  104.  
  105.  
  106. /*=============================== ABUEnvDragMgr::OutlineRegion ================================*/
  107. OSErr    ABUEnvDragMgr::OutlineRegion(void)
  108. {
  109.     OSErr        error = noErr;
  110.     RgnHandle    tempRegion;
  111.     
  112.     //    begin here...
  113.     
  114.     tempRegion = ::NewRgn();
  115.     if (!tempRegion)
  116.         return memFullErr;
  117.     
  118.     //    1.0.6 ty...added check for the dragRegion having been
  119.     //                created properly
  120.     if (this->DoesntHaveDragRegionRef())
  121.         return memFullErr;
  122.         
  123.     ::CopyRgn (this->DragRegionRef(), tempRegion);
  124.     error = ::QDError();
  125.     if (error)
  126.         return error;
  127.         
  128.     ::InsetRgn (tempRegion, 1, 1);
  129.     error = ::QDError();
  130.     if (error)
  131.         return error;
  132.         
  133.     ::DiffRgn (this->DragRegionRef(), tempRegion, this->DragRegionRef());
  134.     error = ::QDError();
  135.     if (error)
  136.         return error;
  137.         
  138.     ::DisposeRgn(tempRegion);
  139.     error = ::QDError();
  140.     return error;
  141.         
  142. } // end OutlineRegion
  143.  
  144.  
  145.  
  146.  
  147. /*=============================== ABUEnvDragMgr::Initialize ================================*/
  148. OSErr    ABUEnvDragMgr::Initialize(void)
  149. {
  150.     OSErr                error;
  151.     
  152.     //    OVERRIDE THIS FUNCTION, but be sure to invoke this one from the
  153.     //    overriding function!
  154.     
  155.     if (!this->IsPresent())
  156.     {
  157.         return paramErr;
  158.     } else if (this->IsDragInitialized()) {
  159.         return noErr;
  160.     } // end if block
  161.     
  162.     error = ::NewDrag(&(this->DragRef()));
  163.     if (error)
  164.         return error;
  165.     
  166.     this->DragInitializedRef() = true;
  167.     this->DragRegionRef() = ::NewRgn();
  168.     if (this->DoesntHaveDragRegionRef())
  169.         return memFullErr;
  170.         
  171.     this->DragUPPRef() = NewDragSendDataProc (SendProc);
  172.     if (this->DoesntHaveDragUPPRef())
  173.         return paramErr;
  174.  
  175.  
  176.     return error;
  177.  
  178. }    // end Initialize
  179.  
  180.  
  181.  
  182.  
  183. /*=============================== ABUEnvDragMgr::Begin ================================*/
  184. OSErr    ABUEnvDragMgr::Begin(void)
  185. {
  186.     OSErr    error = paramErr;
  187.     
  188.     //    OVERRIDE THIS FUNCTION!
  189.     if (this->IsPresent() && this->IsDragInitialized() && this->HasDragMgrEventRef())
  190.     {
  191.         //    set the draggable item's bounding rectangle
  192.         error = this->MakeDragRegion ();
  193.     
  194.         //    1.0.6 ty...extended the error checking the the
  195.         //                line below to avoid region problems.
  196.         //
  197.         if (!error && this->HasDragRegionRef() && this->HasDragRef())
  198.         {
  199.             //    draw a hollow thing...
  200.             error = this->OutlineRegion ();
  201.             if (!error)
  202.                 //    1.0.7 ty...set the drag send proc just in case
  203.                 error = ::SetDragSendProc (this->DragRef(), this->DragUPPRef(), NULL);
  204.  
  205.             if (!error)
  206.                 //    now do the drag...
  207.                 error = ::TrackDrag (this->DragRef(),
  208.                                     this->DragMgrEventRef(),
  209.                                     this->DragRegionRef());
  210.         } else {
  211.             error = paramErr;
  212.         } // end if block
  213.     } // end if block
  214.     
  215.     return error;
  216.  
  217. }    // end Begin
  218.  
  219.  
  220.  
  221.  
  222.  
  223. /*=============================== ABUEnvDragMgr::End ================================*/
  224. OSErr    ABUEnvDragMgr::End(void)
  225. {
  226.     //    OVERRIDE THIS FUNCTION!
  227.     
  228.     if (this->HasDragUPPRef())
  229.     {
  230.         DisposeRoutineDescriptor (this->DragUPPRef());
  231.         this->DragUPPRef() = NULL;
  232.     } // end if block
  233.     
  234.     if (this->HasDragRef() && this->IsPresent())
  235.     {
  236.         ::DisposeDrag(this->DragRef());
  237.         this->DragRef() = NULL;
  238.     } // end if block
  239.         
  240.     if (this->HasDragRegionRef())
  241.     {
  242.         ::DisposeRgn(this->DragRegionRef());
  243.         this->DragRegionRef() = NULL;
  244.     } //
  245.     
  246.     this->DragInitializedRef() = false;
  247.     return noErr;
  248.  
  249. }    // end End
  250.  
  251.  
  252.  
  253.  
  254. /*=============================== ABUEnvDragMgr::GetDropLocationDirectory ================================*/
  255. OSErr    ABUEnvDragMgr::GetDropLocationDirectory( AEDesc *dropLocation,
  256.                                     long *directoryID,
  257.                                     short *volumeID)
  258. {
  259.     OSErr            error;
  260.     AEDesc            targetDescriptor;    //    'fss ' descriptor for target directory
  261.     FSSpec            targetLocation;        //    FSSpec for target directory
  262.     CInfoPBRec        getTargetInfo;        //    paramBlock to get targetDirID
  263.     
  264.     //    Coerce the 'alis' descriptor to a 'fss ' descriptor
  265.     error = ::AECoerceDesc(dropLocation, typeFSS, &targetDescriptor);
  266.     if (error)
  267.         return error; 
  268.     
  269.     //    Extract the FSSpec from targetDescriptor
  270.     ::BlockMove((Ptr)(*targetDescriptor.dataHandle), (Ptr)&targetLocation, sizeof(FSSpec));
  271.     
  272.     error = ::AEDisposeDesc(&targetDescriptor);
  273.     if (error)
  274.         return error;
  275.     
  276.     //    Use PBGetCatInfo to get the directoryID of the target directory
  277.     //    from the FSSpec
  278.     
  279.     getTargetInfo.dirInfo.ioNamePtr = targetLocation.name;
  280.     getTargetInfo.dirInfo.ioVRefNum = targetLocation.vRefNum;
  281.     getTargetInfo.dirInfo.ioFDirIndex = 0;
  282.     getTargetInfo.dirInfo.ioDrDirID = targetLocation.parID;
  283.     
  284.     error = ::PBGetCatInfoSync(&getTargetInfo);
  285.     if (error)
  286.         return error;
  287.     
  288.     //    return directory ID and volume reference number
  289.     
  290.     *directoryID = getTargetInfo.dirInfo.ioDrDirID;
  291.     *volumeID = targetLocation.vRefNum;
  292.     
  293.     return error;
  294. }    // end GetDropLocationDirectory
  295.                                                     
  296.  
  297.  
  298.  
  299. /*=============================== ABUEnvDragMgr::MakeDragRegion ================================*/
  300. OSErr    ABUEnvDragMgr::MakeDragRegion (void)
  301. {
  302.     OSErr            error = noErr;
  303.     RgnHandle        tempRegion;
  304.     Point            offset;
  305.     
  306.     //    begin here...
  307.     
  308.     tempRegion = ::NewRgn();
  309.     if (!(this->HasDragRegionRef() && tempRegion))
  310.         return memFullErr;
  311.     
  312.     offset.h = offset.v = 0;
  313.     ::LocalToGlobal (&offset);
  314.     ::OffsetRect (&(this->DragRectRef()), offset.h, offset.v);
  315.     ::RectRgn (tempRegion, &(this->DragRectRef()));
  316.     error = ::QDError();
  317.     if (error)
  318.         return error;
  319.         
  320.     ::UnionRgn (tempRegion, this->DragRegionRef(), this->DragRegionRef());
  321.     error = ::QDError();
  322.     if (error)
  323.         return error;
  324.         
  325.     ::DisposeRgn(tempRegion);
  326.     error = ::SetDragItemBounds (this->DragRef(),
  327.                                 this->ItemRef(),
  328.                                 &(this->DragRectRef()));
  329.     ::DisposeRgn (tempRegion);
  330.     return error;
  331. } // end MakeDragRegionRef()
  332.  
  333.  
  334.  
  335.  
  336. /*=============================== ABUEnvDragMgr::SendProc ================================*/
  337. //
  338. //    The SendProc() for the class, this static method shown below, is the high-level
  339. //    interface between us, the class, and the DragMgr. Additionally, it is used to invoke
  340. //    the LocalSendProc() of sub-class instances. In this manner we can provide a class-level
  341. //    interface for the DragMgr (static functions) without sacrificing the nice subclassing
  342. //    and virtual function characteristics of C++. The dragSendRefCon is a pointer to the
  343. //    object instance. Neat, huh?
  344. //
  345. pascal    OSErr    ABUEnvDragMgr::SendProc(FlavorType theType,
  346.                                         void *dragSendRefCon,
  347.                                         ItemReference theItemRef,
  348.                                         DragReference theDragRef)
  349. {
  350.     OSErr    error = noErr;
  351.     
  352.  
  353.     if (dragSendRefCon)
  354.     {
  355.         error = ((ABUEnvDragMgr *)(dragSendRefCon))->LocalSendProc (theType,
  356.                                                 dragSendRefCon,
  357.                                                 theItemRef,
  358.                                                 theDragRef);
  359.     } // end if block
  360.     
  361.     return error;
  362. } // end SendProc()
  363.  
  364.  
  365.  
  366.  
  367.  
  368. /*=============================== ABUEnvDragMgr::LocalSendProc ================================*/
  369. //
  370. OSErr    ABUEnvDragMgr::LocalSendProc(FlavorType /*theType*/,
  371.                                     void* /*dragSendRefCon*/,
  372.                                     ItemReference /*theItemRef*/,
  373.                                     DragReference /*theDragRef*/)
  374. {
  375. //#pragma unused (theType, dragSendRefCon, theItemRef, theDragRef)
  376.  
  377.     return noErr;
  378.     
  379. } // end LocalSendProc()
  380.  
  381.  
  382.  
  383. //    end of file.